package com.lyn.solitude.pluginhost.database

import android.app.Application
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log

/**
 *
 * @author longyn 2024/05/24
 * @version 1.0.0
 */
class ISQLiteOpenHelper(application: Application, dbName: String) :
    SQLiteOpenHelper(application, dbName, null, 1) {

    companion object {
        const val TAG = "ISQLiteOpenHelper"
    }

    override fun onCreate(db: SQLiteDatabase?) {
        try {
            val sb: StringBuilder = StringBuilder()
            sb.append("create table plugin(")
            sb.append("id INTEGER PRIMARY KEY AUTOINCREMENT,")
            sb.append("uuid text NOT NULL,")
            sb.append("name text NOT NULL,")
            sb.append("version INTEGER NOT NULL,")
            sb.append("filePath text NOT NULL,")
            sb.append("soFolderPath text NOT NULL,")
            sb.append("mainClassName text NOT NULL,")
            sb.append("time INTEGER NOT NULL")
            sb.append(")")
            db?.execSQL(sb.toString())
            Log.d(TAG, "onCreate")
        } catch (e: Throwable) {
            e.printStackTrace()
        }
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        Log.d(TAG, "onUpgrade")
    }

}